package com.monochromebytes.mononet.virtual;

import java.net.InetSocketAddress;

public class VirtualAddress {

    private final InetSocketAddress localAddress;
    private final InetSocketAddress remoteAddress;
    private final ConnectionID      connectionID;

    public VirtualAddress(InetSocketAddress localAddress, InetSocketAddress remoteAddress,
            ConnectionID connectionID) {
        this.localAddress = localAddress;
        this.remoteAddress = remoteAddress;
        this.connectionID = connectionID;
    }

    public InetSocketAddress getLocalAddress() {
        return this.localAddress;
    }

    public InetSocketAddress getRemoteAddress() {
        return this.remoteAddress;
    }

    public ConnectionID getConnectionID() {
        return this.connectionID;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((connectionID == null) ? 0 : connectionID.hashCode());
        result = prime * result + ((localAddress == null) ? 0 : localAddress.hashCode());
        result = prime * result + ((remoteAddress == null) ? 0 : remoteAddress.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        VirtualAddress other = (VirtualAddress) obj;
        if (connectionID == null) {
            if (other.connectionID != null) {
                return false;
            }
        }
        else if (!connectionID.equals(other.connectionID)) {
            return false;
        }
        if (localAddress == null) {
            if (other.localAddress != null) {
                return false;
            }
        }
        else if (!localAddress.equals(other.localAddress)) {
            return false;
        }
        if (remoteAddress == null) {
            if (other.remoteAddress != null) {
                return false;
            }
        }
        else if (!remoteAddress.equals(other.remoteAddress)) {
            return false;
        }
        return true;
    }
}
